#!/bin/bash

. ${TOOL_DIR}/functions

function brief()
{
    echo "--test-ros2=[no|<path>]"
}

function help()
{
    brief
    cat <<EOF
    If this option is given with a <path> to the ros2 source tree, the full tree will be imported
    on the target under /data/ros2 from which you can execute the ros2 test suite using:

    cd /data/ros2/qnx/test
    ./qnxtest.sh

    NOTE: You must compile the ros2 source tree of the desired target before building
    the vm image.

    The default is no.
EOF
}

function validate() {

	if [ ${OPT_TEST_ROS2} != "no" ]; then
		if [ ! -d "${OPT_TEST_ROS2}" ]; then
			echo "Invalid ros2 source tree '${OPT_TEST_ROS2}'"
			exit 1;
		fi
	else
		exit 0;
	fi
}

function configure()
{
	rm -f output/option_files/*.opt_test_ros2
	if [ "$OPT_TEST_ROS2" != no ]; then
		if [ "${OPT_VERBOSE}" == "yes" ]; then
			echo "Building ros2 file list from ${OPT_TEST_ROS2}"
		fi

		for f in $(find ${OPT_TEST_ROS2} -type f); do
			echo "[perms=0755] ros2/${f#${OPT_TEST_ROS2}/}=${f}" >> output/option_files/data_files.opt_test_ros2
		done;

		case ${OPT_ARCH} in
		x86*)
			ROS2_TEST_PREFIX="nto-${OPT_ARCH}-o";
			;;
		*aarch64*)
			ROS2_TEST_PREFIX="nto-aarch64-le";
			;;
		esac

		# export ros2 options"
		echo "ROS2_TEST_PREFIX=${ROS2_TEST_PREFIX}" >> output/option_files/ifs_env.opt_test_ros2

	fi

	exit 0
}

case "$1" in
	brief)
		brief;;
	help)
		help;;
	validate)
		validate;;
	configure)
		configure;;
	default)
		echo no;;
esac
